
public class Stack<Item>{
    private Node head;
    private int N;
    private class Node{
        Item val;
        Node next;
        public Node(){

        }
        public Node(Item val){
            this.val = val;
        }
    }
    public boolean isEmpty(){
        return N==0;
    }
    public int size(){
        return N;
    }
    public void push(Item item){
        //从栈顶添加元素
        Node oldhead = head;
        head = new Node(item);
        head.next = oldhead;
        N++;
    }
    public Item pop(){
        //从栈顶删除元素
        if(isEmpty()){
            return null;
        }else{
            Item tem = head.val;
            head = head.next;
            N--;
            return tem;
        }

    }
}